﻿using System;
using System.Collections;
using FX.CC.Andon.Entity.BasicDataManage;
using FX.CC.Andon.Service.BasicDataManage;
using FX.CC.Andon.Utility.Json;

namespace FX.CC.Andon.Business.BasicDataManage
{
    /// <summary>
    /// 车间业务层
    /// </summary>
    public class WorkShopBusiness
    {
        private readonly WorkShopService _dal = new WorkShopService();

        /// <summary>
        /// 获取车间绑定下拉列表
        /// </summary>
        /// <returns></returns>
        public string GetWorkShopList()
        {
            return JsonHelper.Encode(_dal.GetWorkShopList());
        }

        /// <summary>
        /// 添加车间
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool AddWorkShop(string data)
        {
            var model = new WorkShopEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.WSID = Guid.NewGuid();
                model.WSCode = row["WSCode"].ToString();
                model.WSName = row["WSName"] != null ? row["WSName"].ToString() : "";
                model.WSDesc = row["WSDesc"] != null ? row["WSDesc"].ToString() : "";
            }
            return _dal.AddWorkShop(model);
        }

        /// <summary>
        /// 修改车间
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool ModifyWorkShop(string data)
        {
            var model = new WorkShopEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.WSID = new Guid(row["WSID"].ToString());
                model.WSCode = row["WSCode"].ToString();
                model.WSName = row["WSName"] != null ? row["WSName"].ToString() : "";
                model.WSDesc = row["WSDesc"] != null ? row["WSDesc"].ToString() : "";
            }
            return _dal.ModifyWorkShop(model);
        }

        /// <summary>
        /// 获取车间单条信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetWorkShopInfo(string id)
        {
            return JsonHelper.Encode(_dal.GetWorkShopInfo(id));
        }

        /// <summary>
        /// 删除车间
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Remove(string id)
        {
            return _dal.Remove(id);
        }

        /// <summary>
        /// 获取车间分页
        /// </summary>
        /// <returns></returns>
        public string GetWorkShopList(WorkShopQcEntity qcmodel)
        {
            var total = _dal.GetWorkShopCount(qcmodel);
            var list = _dal.GetWorkShopList(qcmodel);
            return JsonHelper.Encode(total, list);
        }

        //public string GetWorkShopListByBizDate(string bizDate)
        //{
        //    return JsonHelper.Encode(_dal.GetWorkShopListByBizDate(bizDate));
        //}
    }
}
